package com.harmontronics.hanma.paas.paas.controller;

import com.harmontronics.hanma.paas.paas.annotation.TokenValidSkip;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.GroupMemberUser;
import com.harmontronics.hanma.paas.paas.service.IHmUserGroupMemberService;
import com.harmontronics.hanma.paas.paas.utils.MyBeanUtils;
import java.util.Arrays;
import java.util.List;

import com.harmontronics.hanma.paas.paas.common.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.harmontronics.hanma.paas.paas.service.HmUserGroupMemberAppService;
import com.harmontronics.hanma.paas.paas.dto.iam.input.HmUserGroupMemberCreateInput;
import com.harmontronics.hanma.paas.paas.domain.iam.entity.HmUserGroupMember;


/**
 * 用户组成员个人（部门）
 *
 * @author paas-generator
 * @email paas-generator@harmontronics.com
 * @date 2021-04-07 10:35:20
 */
@RestController
@RequestMapping("/api/hmusergroupmember")
@Api(tags = {"用户组成员个人（部门）"})
public class HmUserGroupMemberController {
    @Autowired
    private IHmUserGroupMemberService hmUserGroupMemberappService;


    @GetMapping("/list")
    @ApiOperation(value = "获取用户组成员")
    public ResponseEntity<List<GroupMemberUser>> list(@RequestParam Long groupId) {
        List<GroupMemberUser> groupMemberUserList = hmUserGroupMemberappService.selectGroupMemberWithGroupId(groupId);
        return ResponseEntity.ok(groupMemberUserList);
    }

    @PostMapping
    @ApiOperation(value = "新增用户组成员")
    @TokenValidSkip
    public ResponseEntity create(@RequestBody List<HmUserGroupMemberCreateInput> userGroupMemberList) {
        List<HmUserGroupMember> groupMemberList = MyBeanUtils.batchTransform(HmUserGroupMember.class,userGroupMemberList);
        hmUserGroupMemberappService.create(groupMemberList);
        return ResponseEntity.ok();
    }

    @DeleteMapping
    @ApiOperation(value = "删除用户组成员")
    public ResponseEntity delete(@RequestParam Long id) {
        hmUserGroupMemberappService.remove(id);
        return ResponseEntity.ok();
    }



}
